<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>用户销售订单列表页面</title>
</head>
<script language="javascript">
function printpage(){
	window.print()
}
</script>
<?php 
include_once("inc.php");
include_once("base.php");
$tb_name = "ordersta";
$where_sql = "usersid=".$_SESSION["id"];
include_once ROOT_PATH."/common/where.php";
$list = db_get_page("select * from $tb_name where $where_sql order by id desc", $page,12);
include_once ROOT_PATH."/common/page.php";
?>
<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" rowspan="2" valign="top" bgcolor="#FFFFFF"></td>
			<td valign="top">
				<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0">
					<tr bgcolor="#FFFFFF">
						<td height="31">
							<div class="title">订单管理</div>
						</td>
					</tr>
				</table>
			</td>
			<td width="16" rowspan="2" bgcolor="#FFFFFF"></td>
		</tr>
		<tr>
			<td valign="top" bgcolor="#F7F8F9">
				<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
					<tr>
						<td colspan="4" height="10"></td>
					</tr>
					<tr>
						<td width="1%">&nbsp;</td>
						<td width="96%">
							<table width="100%" class="cont">
								<tr>
									<td width="1%"></td>
									<td>
										<form id="form1" name="form1" action="?" method="get">
											<input type="text" name="onumber" class="text" value="<?php echo $_REQUEST["onumber"]; ?>" placeholder="输入订单号"/>
											<button type="submit" id="chaxun" class="btn">查询</button>
										</form>
									</td>
								</tr>
							</table>
						</td>
						<td width="1%">&nbsp;</td>
					</tr>
					<tr>
						<td width="1%">&nbsp;</td>
						<td width="96%">
							<form action="?" method="get" name="lsm" id="lsm">
								<input type="hidden" name="chk1" value="ok" />
								<input type="hidden" name="onumber" value="<?php echo $_REQUEST["onumber"]; ?>"/>
								<table width="100%">
									<td colspan="2">
										<table width="100%"  class="cont tr_color">
											<tr>
												<th width="30"></th>
												<th>订单编号</th>
												<th>名称</th>
												<th>单价</th>
												<th>数量</th>
												<th>金额总计</th>
												<th>订单状态</th>
												<th width="150">时间</th>
												<th width="120">操作</th>
											</tr>
											<?php
											foreach($list["data"] as $row) {
												?>
												<tr align="center" class="d">
													<td>
														<input type="checkbox" name="sel_id[]" id="sel_id" value="<?php echo $row['id'];?>">
													</td>
													<td>
														<?php echo db_get_val("orders",$row["ordersid"],"onumber")?>
													</td>
													<td><?php echo db_get_val("goods",$row["goodsid"],"title")?></td>
													<td><?php echo $row['price'];?></td>
													<td><?php echo $row['nums'];?></td>
													<td><?php echo $row['totals'];?></td>
													<td><?php echo $row['zt'];?>
													<?php
													if($row['zt']=="已付款"&&$row['shfs']!="自提"){
														?>
														<br>
														<a href="fahuo.php?id=<?php echo $row['id'];?>">
														<input type="button" value="发货" />
														</a>
													<?php }?>
													</td>
													<td><?php echo $row['addtime'];?></td>
													<td>
														<a href="<?php echo $tb_name;?>_edit.php?ordersid=<?php echo $row['ordersid'];?>&id=<?php echo $row['id'];?>">查看</a>
													</td>
												</tr>
											<?php } ?>
											<tr align="center" class="d">
												<td></td>
												<td colspan="9" align="left">
													&nbsp;&nbsp;
													<input type="checkbox" id="sel_all" value="yes"  onClick="select_all(this.form)">
													<strong>全选</strong>
													<select name="sel_do" size="1" id="sel_do">
														<option value="">选择状态</option>
														<option value="delorders">删除</option>
														<option value="uporders">收货</option>
													</select>
													<input type="submit" value="操作" onClick="return sel_click(this.form)">
												</td>
											</tr>
										</table>
									</td>
									<!-- </tr> -->
								</table>
							</form>
							<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
								<tr>
									<td align="center"><?php echo $page_show;?></td>
								</tr>
							</table>    
						</td>
						<td width="1%">&nbsp;</td>
					</tr>
					<tr><td height="20"></td></tr>
				</table>
			</td>
		</tr>
	</table>
<?php 
function delorders($table,$sel_id) {
		if($table && $sel_id[0]) {
			for ($i=0; $i<count($sel_id); $i++){
				$wheresql=' id in('. $sel_id[$i] .')';
				db_dela("comment","orderstaid=".$sel_id[$i]);
				$sql="delete from `".$table."` where ".$wheresql;
				db_query($sql);
			}
		}
	}
function uporders($table,$sel_id) {
		if($table && $sel_id[0]) {
			for ($i=0; $i<count($sel_id); $i++){
				$wheresql=' id in('. $sel_id[$i] .')';
				$sql="update `".$table."` set zt='已收货' where ".$wheresql;
				//echo $sql;die;
				db_query($sql);
			}
		}
	}
if($_REQUEST["chk1"]=="ok"){
		
		if($_REQUEST["sel_do"]=="delorders"){
			delorders($tb_name,$_REQUEST["sel_id"]);
		}
		elseif($_REQUEST["sel_do"]=="uporders"){
			uporders($tb_name,$_REQUEST["sel_id"]);
		}
		
		else{
			delorders($tb_name,$_REQUEST["sel_id"]);}
	urlMsg("09操作成功", "ordersta_list.php?".$condition);
	}
?>
</body>
</html>